import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/',
      name: 'default',
      redirect: "/login",
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/Login.vue'),
    },
    {
      path: '/manage',
      name: 'manage',
      component: () => import('@/views/Manage.vue'),
      meta: { 
        requireAuth: true
      },
      children:[
        {
          path: '',
          name: 'home',
          redirect: '/manage/train',
        },
        {
          path: 'train',
          name: 'train',
          component: () => import('@/views/train/TrainManagement.vue'),
        },
        {
          path: 'route',
          name: 'route',
          component: () => import('@/views/route/RouteManagement.vue'),
        },
        {
          path: 'order',
          name: 'order',
          component: () => import('@/views/order/OrderManagement.vue'),
        },
        {
          path: 'orderCreate',
          name: 'orderCreate',
          component: () => import('@/views/order/OrderCreate.vue'),
        },
        {
          path: 'orderUpdate',
          name: 'orderUpdate',
          component: () => import('@/views/order/OrderUpdate.vue'),
        },
        {
          path: 'station',
          name: 'station',
          component: () => import('@/views/station/StationManagement.vue'),
        },
        {
          path: 'stationCreateOrUpdate',
          name: 'stationCreateOrUpdate',
          component: () => import('@/views/station/StationCreateOrUpdate.vue'),
        },
        {
          path: 'user',
          name: 'user',
          component: () => import('@/views/user/UserManagement.vue'),
        },
        {
          path: 'userCreateOrUpdate',
          name: 'userCreateOrUpdate',
          component: () => import('@/views/user/UserCreateOrUpdate.vue'),
        },
        {
          path: 'passenger',
          name: 'passenger',
          component: () => import('@/views/passenger/PassengerManagement.vue'),
        },
        {
          path: 'passengerCreateOrUpdate',
          name: 'passengerCreateOrUpdate',
          component: () => import('@/views/passenger/PassengerCreateOrUpdate.vue'),
        },
        {
          path: 'trainCreateOrUpdate',
          name: 'trainCreateOrUpdate',
          component: () => import('@/views/train/TrainCreateOrUpdate.vue'),
        },
        {
          path: 'routeCreateOrUpdate',
          name: 'routeCreateOrUpdate',
          component: () => import('@/views/route/RouteCreateOrUpdate.vue'),
        },
        {
          path: 'statistic',
          name: 'statistic',
          component: () => import('@/views/statistic/Statistic.vue'),
        },
        {
          path: 'dataBaseBackUp',
          name: 'dataBaseBackUp',
          component: () => import('@/views/dataBase/DataBaseBackUp.vue'),
        }
      ]
    },
    {
      path: '/:catchAll(.*)', // 匹配所有未定义的路由
      name: 'notFound',
      component: () => import('@/views/ErrorPage.vue'),
    }
  ],
})

export default router
